home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1833 / 1833.xpi / chrome / yoono.jar / content / yoono / dialogs / changepasswd.js next >
Text File  |  2009-12-16  |  3KB  |  91 lines

  1. const MAXLENGTH = 50;
  2. const MINLENGTH = 6;
  3.  
  4. const DIALOG = document.getElementById('yoono-dialog-changepasswd');
  5.  
  6. const PASSWDXTBOX = document.getElementById('yoono-changepasswd-newpasswd-textbox');
  7. const CONFIRMTXTBOX = document.getElementById('yoono-changepasswd-confirm-newpasswd-textbox');
  8. const CURRENTTXTBOX = document.getElementById('yoono-changepasswd-currentlogin-textbox');
  9.  
  10. const PASSNOMATCHWARN = document.getElementById('yoono-changepasswd-newpasswd-notmatch');
  11. const PASSINVALIDWARN = document.getElementById('yoono-changepasswd-newpasswd-invalid');
  12. const SUCCESSWARN = document.getElementById('yoono-changepasswd-success');
  13.  
  14. const CONNECTERROR = document.getElementById('yoono-changepasswd-connecterror');
  15.  
  16. const IDPASSSTR = YNPREFBRANCH.getCharPref('userid');
  17. const ID = IDPASSSTR.slice(0, IDPASSSTR.indexOf(':'));
  18.  
  19. var serverUrl = YNPREFBRANCH.getCharPref('serverurl');
  20.  
  21. function init() {
  22.    CURRENTTXTBOX.value = ID;
  23.    PASSWDXTBOX.focus();
  24.    centerWindow();
  25. }
  26.  
  27. function validateForm() {
  28.    var input = new inputFields(  PASSWDXTBOX,
  29.                                  CONFIRMTXTBOX
  30.                               );
  31.    // on reinitialise les messages d erreur  
  32.    clearWarnings();
  33.  
  34.    var error = false;
  35.  
  36.    if (input.passwd != input.passwdConfirm) {
  37.       PASSNOMATCHWARN.hidden = false;
  38.       error = true;
  39.    } else if (!validateLoginInput(input.passwd)) {
  40.       PASSINVALIDWARN.hidden = false;
  41.       error = true;
  42.    }
  43.    if (error) {
  44.       PASSWDXTBOX.value = '';
  45.       CONFIRMTXTBOX.value = '';
  46.       PASSWDXTBOX.focus();
  47.       sizeToContent();
  48.       return false;
  49.    } else {
  50.    
  51.       var script = <server-script version="1.0"/>;
  52.       script.appendChild( <context> <user-id> {IDPASSSTR} </user-id> </context>);;
  53.       script.appendChild( <change-login-password login={ID} password={input.passwd}/>);
  54.       // results is an array with request and xml result if successfull
  55.       var results = YOONO_CMPT.sendRequest(serverUrl + 'linkserver', 'POST', 'sync', script, null);
  56.  
  57.       if ('' == results[1]) {
  58.         CONNECTERROR.hidden = false;
  59.         sizeToContent();
  60.          return false;
  61.       }
  62.  
  63.       if (results[1]['display-message'].@code == 'MSG_LOGIN_PASSWORD_CHANGED') {
  64.         try {
  65.          SUCCESSWARN.hidden = false;
  66.          clearWarnings();
  67.          disableTextBoxes();
  68.          sizeToContent();
  69.          YOONO_CMPT.registerUser(ID, input.passwd);
  70.          YOONO_CMPT._globalService.accountsManager.onPostLoginInit(
  71.                  YOONO_CMPT._globalService.accountsManager.YOONO_USER_CHANGED_PWD,
  72.                  YOONO_CMPT.getUserCredential()
  73.                  );
  74.          var pc = YNPREFBRANCH.getIntPref('pwd.changes');
  75.          YNPREFBRANCH.setIntPref('pwd.changes', pc + 1);
  76.          validateForm = function () {};
  77.          DIALOG.buttons="accept";
  78.         } catch(e) {
  79.           return false;
  80.         }
  81.       }
  82.       return false;
  83.    }
  84.    
  85. }
  86.  
  87. function inputFields(passwdField, passwdConfirmField) {
  88.    this.passwd = passwdField.value;
  89.    this.passwdConfirm = passwdConfirmField.value;
  90. }
  91.